import { requestClient } from '#/api/request';
import type {
  InventoryDto,
  CreateInventoryDto,
  UpdateInventoryDto,
  GetInventoryListDto,
  InventoryManagementImportResult,

} from './types';
import type { AbpPagedResult } from '#/api/abp/types';
/**
 * 获取库存列表
 */
export async function getInventories(
  params: GetInventoryListDto,
): Promise<AbpPagedResult<InventoryDto>> {
  return requestClient.get('/api/app/inventory-management', {
    params,
  });
}

/**
 * 获取单个库存信息
 */
export async function getInventory(id: string): Promise<InventoryDto> {
  return requestClient.get(`/api/app/inventory-management/${id}`);
}

/**
 * 创建库存
 */
export async function createInventory(
  data: Partial<CreateInventoryDto>,
): Promise<InventoryDto> {
  return requestClient.post('/api/app/inventory-management', data);
}

/**
 * 更新库存
 */
export async function updateInventory(
  id: string,
  data: Partial<UpdateInventoryDto>,
): Promise<InventoryDto> {
  return requestClient.put(`/api/app/inventory-management/${id}`, data);
}

/**
 * 删除库存
 */
export async function deleteInventory(id: string): Promise<void> {
  return requestClient.delete(`/api/app/inventory-management/${id}`);
}

/**
 * 导出库存模板
 */
export async function exportInventoryTemplate(): Promise<Blob> {
  return requestClient.get('/api/app/inventory-management/export-template', {
    responseType: 'blob',
  });
}

/**
 * 导出库存
 */
export async function exportInventories(ids: string[]): Promise<Blob> {
  return requestClient.post('/api/app/inventory-management/export', null, {
    params: {
      Ids: ids
    },
    paramsSerializer: 'repeat',
    responseType: 'blob',
  });
}

/**
 * 导入库存
 */
export async function importInventories(file: File): Promise<InventoryManagementImportResult> {
  const formData = new FormData();
  formData.append('file', file);
  return requestClient.post('/api/app/inventory-management/import', formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}
